/**
 * Created by nengjian on 2017/5/18.
 */
var Promise = require('bluebird'),
    _ = require('lodash'),
    co = require('co'),

    exports,
    models;

exports = module.exports;

wxings = [
    'article',
    'posts',
    'dashboard',
];

function init(app) {
    //exports.Base = require('./base');

    wxings.forEach(function (name) {
        _.extend(exports, require('./' + name));
        console.log("require('./"+name+")'")
    });

    return Promise.resolve();
}

function _switch(options) {

    function _callfn() {
        var _call;
        wxings.forEach(function (name) {
            if(options.id==name){
                //console.log(require('./' + name));
                _call = require('./' + name)[name].call('',options);
            }
        });
        return _call;
    }

    return co(function *() {
        var _result = yield _callfn();
        //console.log('_result',JSON.stringify(_result))
        return _result;
    }).catch(function (err) {
        console.log("wxing switch error ==>>",err)
    });
}

exports.init = init;
exports.switch = _switch;